//生产管理系统/数据趋势分析/填表
import React, { Component } from "react";
import { connect } from "dva";

import {
    Form,
    Radio,
    Modal,
    Table,
    Select,
    Cascader,
    DatePicker,
    Dropdown,
    Button,
    Icon,
    message,
    Pagination,
    Input,
    TimePicker
} from "antd";
import moment from "moment";
const { TextArea } = Input;

//form表单套件
const FormItem = Form.Item;
const { MonthPicker, RangePicker } = DatePicker;
const Addmodal = Form.create()(
    class extends React.Component {
        state = {
            checkNick: false,
            checkNick1: false
        };

        handleChange = e => {
            if (e == null) {
                this.setState({
                    checkNick: false
                });
            }
            if (e) {
                this.setState({
                    checkNick: true
                });
            }
        };
        handleChange1 = e => {
            if (e == null) {
                this.setState({
                    checkNick1: false
                });
            }
            if (e) {
                this.setState({
                    checkNick1: true
                });
            }
        };

        disabledDate = current => {
            return current > moment().endOf("day");
        };

        onShowChange = (type, e) => {
            let value = e.target.value;

            this.setState({
                [type]: value
            });

            console.log("type:", value);
        };

        onCreate = () => {};

        handleSubmit = e => {
            e.preventDefault();
            this.props.form.validateFields((err, fieldsValue) => {
                console.log(fieldsValue);
            });
        };

        render() {
            const { getFieldDecorator, setFieldsValue } = this.props.form;
            const format = "HH";
            console.log(this.props.ids);
            const data = {
                rules: [{ required: true, message: "请选择日期!" }]
            };

            const { visible, onCancel, onCreate, form, ids } = this.props;
            console.log(typeof this.props.ids);
            if (typeof this.props.ids == "object") {
                return (
                    <Modal
                        destroyOnClose={true}
                        visible={visible}
                        title="编辑记录"
                        okText="保存"
                        cancelText="关闭"
                        onCancel={onCancel}
                        onOk={onCreate}
                    >
                        <Form layout="inline">
                            <FormItem label="日期">
                                {getFieldDecorator("date", {
                                    rules: [
                                        {
                                            required: true,
                                            message: "请选择日期!"
                                        }
                                    ],
                                    initialValue: moment(ids.date)
                                })(
                                    <DatePicker
                                        placeholder="请选择日期"
                                        size="small"
                                        disabledDate={this.disabledDate}
                                        // disabledTime={disabledDateTime}
                                        // showTime={{ defaultValue: moment('00:00:00', 'HH:mm:ss') }}
                                    />
                                )}
                            </FormItem>

                            <FormItem label="扬尘">
                                {getFieldDecorator("raiseDustValue", {
                                    validateTrigger: ["onBlur"],
                                    rules: [
                                        { required: true, message: "必填" },
                                        {
                                            pattern: /^[0-9]+([.]{1}[0-9]{1})?$/,
                                            message: "请输入数字及小数点后一位"
                                        }
                                    ],
                                    initialValue: ids.raiseDustValue
                                })(<Input size="small" />)}
                            </FormItem>
                            <FormItem label="异味">
                                {getFieldDecorator("peculiarSmellValue", {
                                    validateTrigger: ["onBlur"],
                                    rules: [
                                        { required: true, message: "必填" },
                                        {
                                            pattern: /^[0-9]+([.]{1}[0-9]{1})?$/,
                                            message: "请输入数字及小数点后一位"
                                        }
                                    ],
                                    initialValue: ids.peculiarSmellValue
                                })(<Input size="small" />)}
                            </FormItem>
                            <FormItem label="噪音">
                                {getFieldDecorator("noiseValue", {
                                    validateTrigger: ["onBlur"],
                                    rules: [
                                        { required: true, message: "必填" },
                                        {
                                            pattern: /^[0-9]+([.]{1}[0-9]{1})?$/,
                                            message: "请输入数字及小数点后一位"
                                        }
                                    ],
                                    initialValue: ids.noiseValue
                                })(<Input size="small" />)}
                            </FormItem>
                            <FormItem label="记录人">
                                {getFieldDecorator("person", {
                                    validateTrigger: ["onBlur"],
                                    rules: [{ required: true, message: "必填" }],
                                    initialValue: ids.person
                                })(<Input type="textarea" size="small" />)}
                            </FormItem>
                            <FormItem label="备注">
                                {getFieldDecorator("remarks", {
                                    validateTrigger: ["onBlur", "onChange"],
                                    rules: [
                                        { max: 20, message: "最多输入20个字" }
                                    ],
                                    initialValue: ids.remarks
                                })(
                                    <TextArea
                                        type="textarea"
                                        style={{ width: 300 }}
                                    />
                                )}
                            </FormItem>
                        </Form>
                    </Modal>
                );
            }

            return (
                <Modal
                    destroyOnClose={true}
                    visible={visible}
                    title="新增记录"
                    okText="保存"
                    cancelText="关闭"
                    onCancel={onCancel}
                    onOk={onCreate}
                >
                    <Form layout="inline">
                        <FormItem label="日期">
                            {getFieldDecorator("date", data)(
                                <DatePicker
                                    placeholder="请选择日期"
                                    size="small"
                                    disabledDate={this.disabledDate}
                                    // disabledTime={disabledDateTime}
                                    // showTime={{ defaultValue: moment('00:00:00', 'HH:mm:ss') }}
                                />
                            )}
                        </FormItem>

                        <FormItem label="扬尘">
                            {getFieldDecorator("raiseDustValue", {
                                validateTrigger: ["onBlur"],
                                rules: [
                                    { required: true, message: "必填" },
                                    {
                                        pattern: /^[0-9]+([.]{1}[0-9]{1})?$/,
                                        message: "请输入数字及小数点后一位"
                                    }
                                ]
                            })(<Input size="small" />)}
                        </FormItem>
                        <FormItem label="异味">
                            {getFieldDecorator("peculiarSmellValue", {
                                validateTrigger: ["onBlur"],
                                rules: [
                                    { required: true, message: "必填" },
                                    {
                                        pattern: /^[0-9]+([.]{1}[0-9]{1})?$/,
                                        message: "请输入数字及小数点后一位"
                                    }
                                ]
                            })(<Input size="small" />)}
                        </FormItem>
                        <FormItem label="噪音">
                            {getFieldDecorator("noiseValue", {
                                validateTrigger: ["onBlur"],
                                rules: [
                                    { required: true, message: "必填" },
                                    {
                                        pattern: /^[0-9]+([.]{1}[0-9]{1})?$/,
                                        message: "请输入数字及小数点后一位"
                                    }
                                ]
                            })(<Input size="small" />)}
                        </FormItem>
                        <FormItem label="记录人">
                            {getFieldDecorator("person", {
                                validateTrigger: ["onBlur"],
                                rules: [{ required: true, message: "必填" }]
                            })(<Input type="textarea" size="small" />)}
                        </FormItem>
                        <FormItem label="备注">
                            {getFieldDecorator("remarks", {
                                validateTrigger: ["onBlur", "onChange"],
                                rules: [{ max: 20, message: "最多输入20个字" }]
                            })(
                                <TextArea
                                    type="textarea"
                                    style={{ width: 300 }}
                                />
                            )}
                        </FormItem>
                    </Form>
                </Modal>
            );
        }
    }
);

export default connect()(Addmodal);
